             package com.java.diagnostics.visualizer.recommender.pause;
             
             import com.java.diagnostics.visualizer.data.AggregateData;
             import com.java.diagnostics.visualizer.data.DataPoint;
             import com.java.diagnostics.visualizer.data.TupleData;
             import com.java.diagnostics.visualizer.data.axes.Axis;
             import com.java.diagnostics.visualizer.data.axes.XDataAxis;
             import com.java.diagnostics.visualizer.parser.vgc.constants.VGCAxes;
             import com.java.diagnostics.visualizer.parser.vgc.constants.VGCGCScopes;
             import com.java.diagnostics.visualizer.recommender.Recommendation;
             import com.java.diagnostics.visualizer.recommender.RecommendationBase;
             import com.java.diagnostics.visualizer.recommender.util.RecommendationLabels;
             import java.text.MessageFormat;
             import java.util.Iterator;
             import java.util.PriorityQueue;
             
             public class CalculatePauseProperties
               extends RecommendationBase
               implements Recommendation
             {
               protected String label;
               protected int identifier;
               
               public void recommend(AggregateData data)
               {
                 TupleData globalPauseTimeData = data
                   .getTupleData("VGCLabels.pause.times.without.exclusive.access");
                 
                 if (globalPauseTimeData == null) {
                   globalPauseTimeData = 
                     data.getTupleData("VGCLabels.pause.times.with.exclusive.access");
                 }
                 TupleData scopeRecord = data.getTupleData("VGCLabels.gc.scopes");
                 TupleData intervalTimeData = data
                   .getTupleData("VGCLabels.gc.intervals");
                 
                 if (globalPauseTimeData != null) {
                   DataPoint[] globalPauses = globalPauseTimeData.getDataPoints();
                   PriorityQueue<DataPoint> intervals;
                   if (intervalTimeData != null) {
                     intervals = intervalTimeData.getSortedDataPoints();
                   }
                   else
                   {
                     intervals = globalPauseTimeData.getSortedDataPoints();
                   }
                   
                   if ((scopeRecord != null) && (isIBM(data))) {
                     DataPoint[] scopeRecords = scopeRecord.getDataPoints();
                     int pauseNumber = 0;
                     int nurseryNumber = 0;
                     
                     for (int i = 0; i < scopeRecords.length; i++) {
                       if (scopeRecords[i].getRawY() == this.identifier) {
                         pauseNumber++;
                       }
                       if (scopeRecords[i].getRawY() == 5.0D) {
                         nurseryNumber++;
                       }
                     }
                     addToSummary(data, 
                       makeLabel(this.label, RecommendationLabels.NUMBER_OF_COLLECTIONS), 
                       Integer.valueOf(pauseNumber));
                   } else if ((scopeRecord == null) && 
                     (this.identifier == VGCGCScopes.GLOBAL_INT))
                   {
                     addToSummary(data, 
                       makeLabel(this.label, RecommendationLabels.NUMBER_OF_COLLECTIONS), 
                       Integer.valueOf(globalPauses.length));
                   }
                   
                   double totalPause = 0.0D;
                   int meanPauseCount = 0;
                   
                   for (int i = 0; i < globalPauses.length; i++) {
                     if (isCollectionOfGivenScope(scopeRecord, globalPauses[i], 
                       this.identifier)) {
                       totalPause += globalPauses[i].getRawY();
                       meanPauseCount++;
                     }
                   }
                   
                   if (VGCGCScopes.GLOBAL_INT == this.identifier) {
                     calculatePausePropertiesForGlobals(data, this.identifier, this.label, 
                       globalPauseTimeData, intervalTimeData, intervals);
                   } else {
                     double totalInterval = 0.0D;
                     int intervalNumber = 0;
                     
                     Iterator<DataPoint> it = intervals.iterator();
                     while (it.hasNext())
                     {
                       DataPoint interval = (DataPoint)it.next();
                       
                       if (isCollectionOfGivenScope(scopeRecord, interval, 
                         this.identifier)) {
                         double difference = interval.getRawY();
                         totalInterval += difference;
                         intervalNumber++;
                       }
                     }
                     if (intervalNumber > 0) {
                       double interval = totalInterval / intervalNumber;
                       addToSummary(data, makeLabel(this.label, MessageFormat.format(
                         RecommendationLabels.MEAN_INTERVAL, 
                         new Object[] { VGCAxes.MILLISECONDS })), 
                         new Double(interval));
                     }
                   }
                   
                   double duration = totalPause / meanPauseCount;
                   
                   addToSummary(data, makeLabel(this.label, MessageFormat.format(
                     RecommendationLabels.MEAN_PAUSE, 
                     new Object[] { VGCAxes.MILLISECONDS })), new Double(
                     duration));
                 }
               }
               
               private void calculatePausePropertiesForGlobals(AggregateData data, int identifier, String label, TupleData globalPauseTimeData, TupleData intervalTimeData, PriorityQueue<DataPoint> intervals)
               {
                 if ((intervals.size() > 0) && 
                   (!VGCAxes.NUMBER.equals(
                   globalPauseTimeData.getXAxis().getAxis().getBaseUnitName())))
                 {
                   double totalInterval = 0.0D;
                   int intervalCount = 0;
                   double startTime = ((DataPoint)intervals.poll()).getRawX();
                   
                   TupleData scopeRecord = data
                     .getTupleData("VGCLabels.gc.scopes");
                   
                   DataPoint point = (DataPoint)intervals.poll();
                   while (point != null) {
                     if (isCollectionOfGivenScope(scopeRecord, point, identifier)) {
                       double time = point.getRawX();
                       double difference = time - startTime;
                       totalInterval += difference;
                       startTime = time;
                       intervalCount++;
                     }
                     point = (DataPoint)intervals.poll();
                   }
                   double interval = totalInterval / intervalCount;
                   addToSummary(data, makeLabel(label, MessageFormat.format(
                     RecommendationLabels.MEAN_INTERVAL, 
                     new Object[] { VGCAxes.MILLISECONDS })), new Double(
                     interval));
                 }
               }
             }


